package com.esun.rabbit2.viewer.mainact;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.esun.config.Config;

import com.esun.config.Key;
import com.esun.config.Language;

import com.esun.model.UserInfo;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.network.communicater.UserCommunicater;
import com.esun.rabbit2.communicaters.UserAvatarCommunicater;
import com.esun.rabbit2.communicaters.myinfo.CheckBindMobileCommunicater;
import com.esun.rabbit2.communicaters.myinfo.MyInfoCommunicater;
import com.esun.rabbit2.communicaters.recharg.LoginControllerRecharge;
import com.esun.rabbit2.communicaters.recharg.RechargeUserInfo;
import com.esun.rabbit2.communicaters.recharg.UserInfoDetailController;

import com.esun.rabbit2.viewer.LoginAct;
import com.esun.rabbit2.viewer.MainAct;
import com.esun.rabbit2.viewer.RegistAct;
import com.esun.rabbit2.viewer.mainact.mylotteryact.accountdetail.AccountDetailListActGroup;
import com.esun.rabbit2.viewer.mainact.mylotteryact.banckbind.BankCardBindingAct;
import com.esun.rabbit2.viewer.mainact.mylotteryact.banckbind.UninBindingWebAct;
import com.esun.rabbit2.viewer.mainact.mylotteryact.bindmobile.BindMobile_Bind;
import com.esun.rabbit2.viewer.mainact.mylotteryact.bindmobile.BindMobileUnBindAct;
import com.esun.rabbit2.viewer.mainact.mylotteryact.changepassword.ChangePasswordAct;
import com.esun.rabbit2.viewer.mainact.mylotteryact.lotteryrecord.LotteryRecordAgp;
import com.esun.rabbit2.viewer.mainact.mylotteryact.myinfo.NewMyInfoAct;
import com.esun.rabbit2.viewer.mainact.mylotteryact.recharg.RechargeMenuPage;
import com.esun.rabbit2.viewer.mainact.mylotteryact.recharg.RechargeUninBinding;
import com.esun.rabbit2.viewer.mainact.mylotteryact.trackingrecord.TrackingRecordActGroup;
import com.esun.rabbit2.viewer.mainact.mylotteryact.withdrawal.WithdrawalAct;
import com.esun.ui.R;
import com.esun.util.ViewerUtil;
import com.esun.util.img.ImageUtils;
import com.esun.util.img.db.ImageDB;
import com.esun.util.log.EDebug;

/**
 * @Title: MyLotteryAct.java
 * @Package com.esun.ui
 * @Description: (我的彩票页面Activity)
 * @author City jiangsy@500wan.com
 * @date 2011-5-13 下午05:22:23 copy right 深圳市易讯天空网络技术有限公司
 */
public class MyLotteryAct extends Activity implements OnClickListener {

	/** 2011-07-02 Miko 添加 */
	private Button btnRecharge; // 充值按钮
	private Button btnBanckBind; // 银行卡绑定按钮
	private Button btnWithDrawal; // 提款按钮
	private Button btnBindMobile; // 绑定手机号
	private Button btnChangePassword; // 修改密码
	private Button btnMyInfo; // 个人信息
	private Button btnLogin; // 登陆按钮
	private ImageButton btnRefresh; // 刷新按钮

	private ProgressDialog progress;
	private ProgressBar progressBar;

	private Intent intent;

	private LoginControllerRecharge loginRecharge = new LoginControllerRecharge();
	private UserInfoDetailController detailInfoController = new UserInfoDetailController();
	private CheckBindMobileCommunicater cheBindState = new CheckBindMobileCommunicater();

	private String CURRENT_LAYOUT_NUM = "current_layout_num";

	private Handler handler;

	private final int UNIN_PREPARE_OK = 10001;
	private final int NOT_BINDING_UNIN_CARD = 10002;

	private final int PREPARE_FAILED = 111111;
	private final int MOBILE_NOT_BIND = 9999;
	private final int MOBILE_BINDED = 88888;
	private final int REFRESH_SUCCESS = 1000012;
	private final int REFRESH_FAILED = 100002;

	/** 2011-08-08 city add for uninbinding set */
	private final int IS_RELOGIN_SUCCEED = 10003;
	private final int IS_RELOGIN_FAIL = 10004;
	private UserCommunicater userCommunicater;

	private Button btnLotteryRecord;
	private Button btnTrackingRecord;
	private Button btnAccountDetail;

	private LinearLayout localInfoContainer;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mylottery_act);

		init();
		initHandler();
	}

	/** 2011-07-02 Miko 添加 */
	private void init() {

		btnRecharge = (Button) this.findViewById(R.id.mylottery_act_btn_recharge);
		btnRecharge.setOnClickListener(this);

		btnBanckBind = (Button) this.findViewById(R.id.mylottery_act_btn_bankBind);
		btnBanckBind.setOnClickListener(this);

		btnWithDrawal = (Button) this.findViewById(R.id.mylottery_act_btn_withdrawal);
		btnWithDrawal.setOnClickListener(this);

		btnBindMobile = (Button) this.findViewById(R.id.mylottery_act_btn_bindMobile);
		btnBindMobile.setOnClickListener(this);

		btnChangePassword = (Button) this.findViewById(R.id.mylottery_act_btn_changePassword);
		btnChangePassword.setOnClickListener(this);

		btnMyInfo = (Button) this.findViewById(R.id.mylottery_act_btn_myInfo);
		btnMyInfo.setOnClickListener(this);

		btnLotteryRecord = (Button) findViewById(R.id.mylotteryact_btn_gcjl);
		btnLotteryRecord.setOnClickListener(this);

		btnTrackingRecord = (Button) findViewById(R.id.mylotteryact_btn_trackingRecord);
		btnTrackingRecord.setOnClickListener(this);

		btnAccountDetail = (Button) findViewById(R.id.mylottery_act_btn_acountDetail);
		btnAccountDetail.setOnClickListener(this);

		localInfoContainer = (LinearLayout) this.findViewById(R.id.mylottery_act_locaInfoContainer);

		btnLogin = (Button) this.findViewById(R.id.mylottery_act_btn_login);
		btnLogin.setOnClickListener(this);

		btnRefresh = (ImageButton) this.findViewById(R.id.mylottery_act_btn_refresh);
		btnRefresh.setOnClickListener(this);

		progressBar = (ProgressBar) this.findViewById(R.id.lotteryinfoact_pbr_refresh);
		progressBar.setVisibility(View.INVISIBLE);
		btnRefresh.setImageResource(R.drawable.tbgn_icon_update_20x20);

		userCommunicater = new UserCommunicater();

	}

	/** 2011-07-02 Miko 添加 */
	private void showProgress(String msg) {
		if (progress == null) {
			progress = ViewerUtil.showProgressDialog(this, msg);
		}
		progress.show();
	}

	/** 2011-07-02 Miko 添加 */
	private void initHandler() {
		handler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);

				switch (msg.what) {

				case UNIN_PREPARE_OK:

					// 响应哪个按钮的操作
					int witchBtn = (Integer) msg.obj;

					switch (witchBtn) {
					case R.id.mylottery_act_btn_bankBind:
						MyLotteryAct.this.startActivity(new Intent().putExtra("TAG", Config.NUM0).setClass(MyLotteryAct.this, BankCardBindingAct.class));
						if (progress != null) {
							progress.dismiss();
						}
						break;

					case R.id.mylottery_act_btn_withdrawal:
						MyLotteryAct.this.startActivity(new Intent().setClass(MyLotteryAct.this, WithdrawalAct.class));
						if (progress != null) {
							progress.dismiss();
						}
						break;

					default:
						break;
					}

					break;

				case NOT_BINDING_UNIN_CARD:

					MyLotteryAct.this.startActivity(new Intent().setClass(MyLotteryAct.this, UninBindingWebAct.class));
					if (progress != null) {
						progress.dismiss();
					}

					break;

				case PREPARE_FAILED:

					if (progress != null) {
						progress.dismiss();
					}

					ViewerUtil.showTipDialog(MyLotteryAct.this, "获取用户信息失败!", false);

					break;

				case MOBILE_BINDED:

					MyLotteryAct.this.startActivity(new Intent().setClass(MyLotteryAct.this, BindMobile_Bind.class));
					if (progress != null) {
						progress.dismiss();
					}

					break;

				case MOBILE_NOT_BIND:

					Intent intent = new Intent();
					intent.putExtra(Key.KEY_STATE, Config.NUM1);
					intent.putExtra(Key.KEY_MOBILENUM, "");
					startActivity(intent.setClass(MyLotteryAct.this, BindMobileUnBindAct.class));

					if (progress != null) {
						progress.dismiss();
					}

					break;

				case REFRESH_SUCCESS:

					if (progress != null) {
						progress.dismiss();
					}

					EDebug.o(this, "【我的彩票刷新成功】");
					if (UserInfo.getUserInfo().getUserSession().length() > 3) {
						btnLogin.setVisibility(View.INVISIBLE);

						btnRefresh.setVisibility(View.VISIBLE);
						btnRefresh.setImageResource(R.drawable.tbgn_icon_update_20x20);
						progressBar.setVisibility(View.INVISIBLE);

						localInfoContainer.removeAllViews();
						localInfoContainer.addView(getLocalInfo());

					} else {
						btnLogin.setVisibility(View.VISIBLE);
						btnRefresh.setVisibility(View.INVISIBLE);
						progressBar.setVisibility(View.INVISIBLE);
						localInfoContainer.removeAllViews();
						View noLogin = MyLotteryAct.this.getLayoutInflater().inflate(R.layout.mylottery_line_localinfo_no_login, null);

						LayoutParams param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
						param.topMargin = 15;
						localInfoContainer.addView(noLogin, param);
					}
					break;

				case REFRESH_FAILED:

					if (progress != null) {
						progress.dismiss();
					}

					EDebug.o(this, "【我的彩票刷新失败】");
					if (UserInfo.getUserInfo().getUserSession().length() > 3) {
						btnLogin.setVisibility(View.INVISIBLE);

						btnRefresh.setVisibility(View.VISIBLE);
						btnRefresh.setImageResource(R.drawable.tbgn_icon_update_20x20);
						progressBar.setVisibility(View.INVISIBLE);

						localInfoContainer.removeAllViews();
						localInfoContainer.addView(getLocalInfo());

					} else {
						btnLogin.setVisibility(View.VISIBLE);
						btnRefresh.setVisibility(View.INVISIBLE);
						progressBar.setVisibility(View.INVISIBLE);
						localInfoContainer.removeAllViews();
						View noLogin = MyLotteryAct.this.getLayoutInflater().inflate(R.layout.mylottery_line_localinfo_no_login, null);

						LayoutParams param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
						param.topMargin = 15;
						localInfoContainer.addView(noLogin, param);
					}
					break;

				case IS_RELOGIN_SUCCEED:
					updataUserInfo();
					break;

				case Config.CONNECTION_FAIL:

					if (progress != null) {
						progress.dismiss();
					}
					Toast.makeText(MyLotteryAct.this, Language.STR_CONNECTIONFAIL.toString(), Toast.LENGTH_SHORT).show();
					// ViewerUtil.showTipDialog(MyLotteryAct.this, Language.STR_CONNECTIONFAIL, false);

					break;

				default:
					break;

				}
			}
		};
	}

	/** 2011-07-02 Miko 添加 */
	@Override
	public void onClick(View v) {

		if (UserInfo.getUserInfo().getUserSession().length() > 3) {
			switch (v.getId()) {
			case R.id.mylottery_act_btn_recharge:

				// String activityState = LoadingInfo.getInstance().getIsloadwebview();
				// if (activityState.equals(Config.NUM1)) {
				// // 在活动期间，进入webview
				// String ck = UserInfo.getUserInfo().getUserSession();
				// String userName = UserInfo.getUserInfo().getUserName();
				// String userPwd = UserInfo.getUserInfo().getUserPwd();
				// String channel = DistributionChannels.QUDAO;
				// String platform = Config.ANDROID;
				// String version;
				// try {
				// version = MyLotteryAct.this.getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
				// } catch (NameNotFoundException e) {
				// version = Config.NUM0;
				// }
				// String url = Config.ACTIVITY_RECHARGE_MENU_URL + "?ck=" + ck + "&username=" + userName + "&userpwd=" + userPwd + "&channel=" + channel + "&platform=" + platform
				// + "&version="
				// + version;
				// startActivity(new Intent(MyLotteryAct.this, ActivityWebViewActivity.class).putExtra(Key.KEY_URL, url));
				// } else {
				startActivity(new Intent().setClass(this, RechargeMenuPage.class));
				// }

				break;

			case R.id.mylottery_act_btn_bankBind:

				showProgress("获取用户信息...");
				prepareUnin(v.getId());

				break;

			case R.id.mylottery_act_btn_withdrawal:

				showProgress("获取用户信息...");
				prepareUnin(v.getId());

				break;

			case R.id.mylottery_act_btn_bindMobile:

				showProgress("获取用户信息...");
				checkBindMobile();

				break;

			case R.id.mylottery_act_btn_changePassword:

				startActivity(new Intent().setClass(this, ChangePasswordAct.class));

				break;

			case R.id.mylottery_act_btn_myInfo:

				startActivity(new Intent().setClass(this, NewMyInfoAct.class));

				break;

			case R.id.mylotteryact_btn_gcjl:

				intent = new Intent();
				intent.setClass(MyLotteryAct.this, LotteryRecordAgp.class);
				startActivity(intent);

				break;

			case R.id.mylotteryact_btn_trackingRecord:

				intent = new Intent();
				intent.setClass(MyLotteryAct.this, TrackingRecordActGroup.class);
				startActivity(intent);

				break;

			case R.id.mylottery_act_btn_refresh:

				// showProgress("获取用户信息...");
				btnRefresh.setImageBitmap(null);
				progressBar.setVisibility(View.VISIBLE);
				refresh();

				break;

			case R.id.mylottery_act_btn_acountDetail:

				intent = new Intent();
				intent.setClass(MyLotteryAct.this, AccountDetailListActGroup.class);
				startActivity(intent);

				break;

			default:
				break;
			}
		} else {
			startActivity(new Intent().setClass(this, LoginAct.class));
		}
	}

	private void refresh() {

		new Thread() {

			@Override
			public void run() {
				super.run();

				try {
					if (new MyInfoCommunicater().getMyInfo()) {
						Message msg = handler.obtainMessage(REFRESH_SUCCESS);
						handler.sendMessage(msg);
					} else {
						Message msg = handler.obtainMessage(REFRESH_FAILED);
						handler.sendMessage(msg);
					}
				} catch (Exception e) {
					Message msg = handler.obtainMessage(Config.CONNECTION_FAIL);
					handler.sendMessage(msg);
				}
			}
		}.start();
	}

	private void checkBindMobile() {
		new Thread() {

			@Override
			public void run() {
				super.run();

				try {
					if (cheBindState.check()) {
						Message msg = handler.obtainMessage(MOBILE_BINDED);
						handler.sendMessage(msg);
					} else {
						Message msg = handler.obtainMessage(MOBILE_NOT_BIND);
						handler.sendMessage(msg);
					}
				} catch (Exception e) {
					Message msg = handler.obtainMessage(Config.CONNECTION_FAIL);
					handler.sendMessage(msg);
				}

			}
		}.start();
	}

	private void prepareUnin(final int btnId) {
		new Thread() {
			@Override
			public void run() {
				super.run();

				// 是否登陆成功
				if (checkUserLogin()) {

					// 是否获取用户详情成功
					if (detailInfoController.getUserInfoDetail(UserInfo.getUserInfo().getUserName(), RechargeUserInfo.getUserInfo().getSessionId()).length > 1) {

						// 是否绑定银行卡
						if (RechargeUserInfo.getUserInfo().isBandingCard()) {

							Message msg = handler.obtainMessage(UNIN_PREPARE_OK, btnId);
							handler.sendMessage(msg);

						} else {
							Message msg = handler.obtainMessage(NOT_BINDING_UNIN_CARD);
							handler.sendMessage(msg);
						}
					} else {
						Message msg = handler.obtainMessage(PREPARE_FAILED);
						handler.sendMessage(msg);
					}

				} else {
					Message msg = handler.obtainMessage(PREPARE_FAILED);
					handler.sendMessage(msg);
				}
			}
		}.start();
	}

	private boolean checkUserLogin() {

		// if (RechargeUserInfo.getUserInfo().getSessionId().length() > 5) {
		// return true;
		// } else {
		boolean b = false;
		try {
			b = loginRecharge.login(UserInfo.getUserInfo().getUserName(), UserInfo.getUserInfo().getUserPwd());
			EDebug.o(MyLotteryAct.this, "is do rechargeLogin <<<<<<<<<<++++++++++");
		} catch (Exception e) {
			EDebug.o(this, "Error" + e.getLocalizedMessage());
			b = false;
		}
		return b;
		// }
	}

	@Override
	protected void onResume() {
		super.onResume();
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());

		EDebug.o(this, "【我的彩票 onResume】");

		if (UserInfo.getUserInfo().getUserSession().length() > 3) {
			OptionAct.isLoginSucceed = false;
			View view = this.getLayoutInflater().inflate(R.layout.mylottery_line_localinfo, null);

			TextView tvName = (TextView) view.findViewById(R.id.mylottery_line_locainfo_tv_name);
			tvName.setText(UserInfo.getUserInfo().getUserName());

			TextView tvBalance = (TextView) view.findViewById(R.id.mylottery_line_locainfo_tv_balance);
			tvBalance.setText("￥" + UserInfo.getUserInfo().getUserBalance());

			localInfoContainer.removeAllViews();
			localInfoContainer.addView(view);

			if (handler != null) {
				refresh();
			}

		} else {
			btnLogin.setVisibility(View.VISIBLE);
			btnRefresh.setVisibility(View.INVISIBLE);
			localInfoContainer.removeAllViews();
			View noLogin = this.getLayoutInflater().inflate(R.layout.mylottery_line_localinfo_no_login, null);

			LayoutParams param = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			param.topMargin = 15;
			localInfoContainer.addView(noLogin, param);
		}

		if (RegistAct.isRegistSucceed) {
			showRegistSucceedDialog();
			RegistAct.isRegistSucceed = false;
		}

		if (UserInfo.getUserInfo().isRechargeSucceed()) {
			UserInfo.getUserInfo().setRechargeSucceed(false);
			showRechargeSucceedDialog();
		}
	}

	private void showRechargeSucceedDialog() {
		final Dialog rechargeSucceedDialog = new Dialog(MyLotteryAct.this, R.style.dialog);
		UserInfo.getUserInfo().setBuyingRecharge(false);
		rechargeSucceedDialog.getWindow().setContentView(R.layout.viewerutil_dialog_buyingrecharge);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.viewerutildialogbuyingrecharge_btn_goon:
					rechargeSucceedDialog.dismiss();
					doReLogin();
					break;

				case R.id.viewerutildialogbuyingrecharge_btn_toHall:
					rechargeSucceedDialog.dismiss();
					((MainAct) MyLotteryAct.this.getParent()).setChildActivity(MainAct.LOTTERY_HALL_ACTIVITY);
					break;
				default:
					break;
				}
			}
		};

		/** 2011-08-08 city add for uninbinding set */
		if (RechargeUninBinding.isRechargeSucceed) {
			RechargeUninBinding.isRechargeSucceed = false;
			((TextView) rechargeSucceedDialog.getWindow().findViewById(R.id.viewerutildialogbuyingrecharge_tv_msg)).setText("您的银行卡充值订单提交成功!您将使用绑定的银行卡:" + RechargeUserInfo.getUserInfo().getCardNum()
					+ "进行支付,请留意银联02096585的来电。(如您第一次使用建行充值,为了保证您的交易安全,银联将会审核您的资料,来电可能延迟3分钟,请耐心等候)");
		}

		Button btnGoon = (Button) rechargeSucceedDialog.getWindow().findViewById(R.id.viewerutildialogbuyingrecharge_btn_goon);
		btnGoon.setText("查看账户");
		btnGoon.setOnClickListener(listener);
		Button btnToHall = (Button) rechargeSucceedDialog.getWindow().findViewById(R.id.viewerutildialogbuyingrecharge_btn_toHall);
		btnToHall.setOnClickListener(listener);
		rechargeSucceedDialog.show();
	}

	private View getLocalInfo() {

		View view = this.getLayoutInflater().inflate(R.layout.mylottery_line_localinfo, null);

		TextView tvName = (TextView) view.findViewById(R.id.mylottery_line_locainfo_tv_name);
		tvName.setText(UserInfo.getUserInfo().getUserName());

		TextView tvBalance = (TextView) view.findViewById(R.id.mylottery_line_locainfo_tv_balance);
		tvBalance.setText("￥" + UserInfo.getUserInfo().getUserBalance());

		ImageView img = (ImageView) view.findViewById(R.id.mylottery_line_locainfo_img_avatar);
		setAvatar(img);
		return view;
	}

	private void setAvatar(final ImageView image) {

		final int getImageSuccess = 10001;
		final int getImageFailed = 10002;

		final Handler avaterHandler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				switch (msg.what) {
				case getImageSuccess:

					Bitmap bm = (Bitmap) msg.obj;
					image.setImageBitmap(bm);
					break;

				case getImageFailed:
					break;

				default:
					break;
				}
			}
		};

		new Thread() {

			@Override
			public void run() {
				super.run();

				try {
					UserAvatarCommunicater avatar = new UserAvatarCommunicater();
					if (avatar.getAvatar(UserInfo.getUserInfo().getUserName())) {
						Bitmap bm = null;
						String name = UserInfo.getUserInfo().getAvatarAdd();
						ImageDB.getImageDB().open(MyLotteryAct.this);

						bm = ImageUtils.getLocalImg(name);

						if (bm == null) {
							bm = ImageUtils.downLoadImg(name);
							if (bm != null) {
								Message msg = avaterHandler.obtainMessage(getImageSuccess, bm);
								avaterHandler.sendMessage(msg);
								ImageUtils.saveImg(name, bm);
							}
						} else {
							Message msg = avaterHandler.obtainMessage(getImageSuccess, bm);
							avaterHandler.sendMessage(msg);
						}
						ImageDB.getImageDB().close();
					}
				} catch (Exception e) {

				}

			}
		}.start();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Activity parent = getParent();
			if (parent != null) {
				parent.onKeyDown(keyCode, event);
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onPause() {
		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	private void showRegistSucceedDialog() {
		final Dialog registSucceedDialog = new Dialog(MyLotteryAct.this, R.style.dialog);
		registSucceedDialog.getWindow().setContentView(R.layout.viewerutil_dialog_registsucceed);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				switch (v.getId()) {
				case R.id.viewerutildialogregistsucceed_btn_cancel:
					((MainAct) MyLotteryAct.this.getParent()).setChildActivity(MainAct.LOTTERY_HALL_ACTIVITY);
					registSucceedDialog.dismiss();
					break;

				case R.id.viewerutildialogregistsucceed_btn_recharge:
					registSucceedDialog.dismiss();
					Intent intent = new Intent();
					intent.setClass((Activity) MyLotteryAct.this, RechargeMenuPage.class);
					MyLotteryAct.this.startActivity(intent);
					UserInfo.getUserInfo().setBuyingRecharge(true);
					break;
				default:
					break;
				}
			}
		};
		Button btnCancel = (Button) registSucceedDialog.getWindow().findViewById(R.id.viewerutildialogregistsucceed_btn_cancel);
		btnCancel.setOnClickListener(listener);
		btnCancel.setText("购彩大厅");
		Button btnRecharge = (Button) registSucceedDialog.getWindow().findViewById(R.id.viewerutildialogregistsucceed_btn_recharge);
		btnRecharge.setOnClickListener(listener);
		registSucceedDialog.show();
	}

	/** 2011-08-08 city add for uninbinding set */
	private void doReLogin() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					boolean b = userCommunicater.isLoginSucceed(UserInfo.getUserInfo().getUserName(), UserInfo.getUserInfo().getUserPwd());
					if (b) {
						Message msg = handler.obtainMessage(IS_RELOGIN_SUCCEED);
						handler.sendMessage(msg);
					} else {
						Message msg = handler.obtainMessage(IS_RELOGIN_FAIL);
						handler.sendMessage(msg);
					}
				} catch (Exception e) {
					Message msg = handler.obtainMessage(IS_RELOGIN_FAIL);
					handler.sendMessage(msg);
				}
			}
		}.start();
	}

	private void updataUserInfo() {
		userCommunicater.updataUserInfo();
		View view = this.getLayoutInflater().inflate(R.layout.mylottery_line_localinfo, null);

		TextView tvName = (TextView) view.findViewById(R.id.mylottery_line_locainfo_tv_name);
		tvName.setText(UserInfo.getUserInfo().getUserName());

		TextView tvBalance = (TextView) view.findViewById(R.id.mylottery_line_locainfo_tv_balance);
		tvBalance.setText("￥" + UserInfo.getUserInfo().getUserBalance());

		localInfoContainer.removeAllViews();
		localInfoContainer.addView(view);

		if (handler != null) {
			refresh();
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		EDebug.o(MyLotteryAct.this, "shit！！翔~，onActivityResult被调用");
		switch (requestCode) {
		case RechargeMenuPage.REQUEST_CODE_BANKCAD:
			if (resultCode == RechargeMenuPage.RESULT_CODE_TO_CENTER) {
				EDebug.o(MyLotteryAct.this, "查看账户");

				((MainAct) MyLotteryAct.this.getParent()).setChildActivity(MainAct.MY_LOTTERY_ACTIVITY);

			} else if (resultCode == RechargeMenuPage.RESULT_CODE_TO_BUY_LOTTERY) {
				EDebug.o(MyLotteryAct.this, "立即购彩");
				((MainAct) MyLotteryAct.this.getParent()).setChildActivity(MainAct.LOTTERY_HALL_ACTIVITY);

			}
			break;

		default:
			break;
		}
	}

}
